package com.spring.appservice.web.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.fasterxml.jackson.databind.util.JSONPObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.common.collect.Maps;
import com.mangofactory.swagger.annotations.ApiIgnore;
import com.spring.appservice.web.service.MainShowService;
import com.spring.security.core.util.ApplicationUtils;

@Controller
@RequestMapping(value = "/me")
@ApiIgnore
public class MeController {
@Resource private MainShowService mainShowService;
	
	//获取课程列表
    @RequestMapping(value = "/lessonList")
    @ResponseBody
    public Object zoneInfo(String attendType, String startTime,String endTime, String skip,
    		String rows, String pageSize, String pageIndex,String token,String callback) throws Exception{
    	Map<String,Object> rt = Maps.newHashMap();
    	try{
    		rt = mainShowService.lessonList(attendType, startTime, endTime, skip, rows, pageSize, pageIndex,token);
    	}catch(Exception e){
    		rt.put(ApplicationUtils.STATUS, "0");
    		rt.put(ApplicationUtils.MSG, "系统异常");
    		e.printStackTrace();
    	}
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, rt);
        }else{
        	return rt;
        }
    }

    //获取课程详细
    @RequestMapping(value = "/lessonDetail")
    @ResponseBody
    public Object lessonDetail(String lessonId,String token,String callback) throws Exception{
    	Map<String,Object> rt = Maps.newHashMap();
    	try{
    		rt = mainShowService.lessonDetail(token, lessonId);
    	}catch(Exception e){
    		rt.put(ApplicationUtils.STATUS, "0");
    		rt.put(ApplicationUtils.MSG, "系统异常");
    		e.printStackTrace();
    	}
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, rt);
        }else{
        	return rt;
        }
    }

    
        //获取课程详细
    @RequestMapping(value = "/userPackage")
    @ResponseBody
    public Object userPackage(String userPackageId,String callback) throws Exception{
    	Map<String,Object> rt = Maps.newHashMap();
    	try{
    		rt = mainShowService.userPackage(userPackageId);
    	}catch(Exception e){
    		rt.put(ApplicationUtils.STATUS, "0");
    		rt.put(ApplicationUtils.MSG, "系统异常");
    		e.printStackTrace();
    	}
        if(ApplicationUtils.isNotNull(callback)){
        	return new JSONPObject(callback, rt);
        }else{
        	return rt;
        }
    }
    
    
    //获取课程详细
@RequestMapping(value = "/consumingRecord")
@ResponseBody
public Object consumingRecord(String token,String id, String idType, String skip, String rows,
		String pageSize, String pageIndex,String callback) throws Exception{
	Map<String,Object> rt = Maps.newHashMap();
	try{
		rt = mainShowService.consumingRecord(token, id, idType, skip, rows, pageSize, pageIndex);
	}catch(Exception e){
		rt.put(ApplicationUtils.STATUS, "0");
		rt.put(ApplicationUtils.MSG, "系统异常");
		e.printStackTrace();
	}
    if(ApplicationUtils.isNotNull(callback)){
    	return new JSONPObject(callback, rt);
    }else{
    	return rt;
    }
}


    //获取课程详细
@RequestMapping(value = "/lessonComments")
@ResponseBody
public Object getCourseComment(String lessonId, String skip, String rows, String pageSize, String pageIndex,
		String callback) throws Exception{
	Map<String,Object> rt = Maps.newHashMap();
	try{
		rt = mainShowService.getCourseComment(lessonId, skip, rows, pageSize, pageIndex);
	}catch(Exception e){
		rt.put(ApplicationUtils.STATUS, "0");
		rt.put(ApplicationUtils.MSG, "系统异常");
		e.printStackTrace();
	}
    if(ApplicationUtils.isNotNull(callback)){
    	return new JSONPObject(callback, rt);
    }else{
    	return rt;
    }
}

//评论课程
@RequestMapping(value = "/commentLesson")
@ResponseBody
public Object commentLesson(String token,String lessonId, String content, String score,String callback) throws Exception{
	Map<String,Object> rt = Maps.newHashMap();
	try{
		rt = mainShowService.commentLesson(token, lessonId, content, score);
	}catch(Exception e){
		rt.put(ApplicationUtils.STATUS, "0");
		rt.put(ApplicationUtils.MSG, "系统异常");
		e.printStackTrace();
	}
    if(ApplicationUtils.isNotNull(callback)){
    	return new JSONPObject(callback, rt);
    }else{
    	return rt;
    }
}




@RequestMapping(value = "/feedback")
@ResponseBody
public Object feedback(String userID,String feedbackTypeCode, String content, String mobile, String name,String callback) throws Exception{
	Map<String,Object> rt = Maps.newHashMap();
	try{
		rt = mainShowService.feedback(userID,feedbackTypeCode,content, mobile, name);
	}catch(Exception e){
		rt.put(ApplicationUtils.STATUS, "0");
		rt.put(ApplicationUtils.MSG, "系统异常");
		e.printStackTrace();
	}
  if(ApplicationUtils.isNotNull(callback)){
  	return new JSONPObject(callback, rt);
  }else{
  	return rt;
  }
}


//获取会员卡状态
@RequestMapping(value = "/memberCard")
@ResponseBody
public Object memberCard(String token,String callback) throws Exception{
	Map<String,Object> rt = Maps.newHashMap();
	try{
		rt = mainShowService.getMemberCardStatus(token);
	}catch(Exception e){
		rt.put(ApplicationUtils.STATUS, "0");
		rt.put(ApplicationUtils.MSG, "系统异常");
		e.printStackTrace();
	}
if(ApplicationUtils.isNotNull(callback)){
	return new JSONPObject(callback, rt);
}else{
	return rt;
}
}




//挂失会员卡
@RequestMapping(value = "/reportLoss")
@ResponseBody
public Object reportLoss(String memberCard,String callback,String token,HttpServletRequest request
) throws Exception{
	Map<String,Object> rt = Maps.newHashMap();
	try{
		rt = mainShowService.updateMemberIsValid(memberCard,token,request);
	}catch(Exception e){
		rt.put(ApplicationUtils.STATUS, "0");
		rt.put(ApplicationUtils.MSG, "系统异常");
		e.printStackTrace();
	}
if(ApplicationUtils.isNotNull(callback)){
	return new JSONPObject(callback, rt);
}else{
	return rt;
}
}



//


}
